package com.googlecode.framework.core.exception.monitor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;


/**
 * 异常监听拦截器
 * 
 * @author xiayg
 *
 */
public class ExceptionMonitorMethodInterceptor implements MethodInterceptor {
    
    /**
     * 异常监听器
     */
    protected ExceptionMonitor exceptionMonitor;

    /*
     * (non-Javadoc)
     * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
     */
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        try {
            return invocation.proceed();
        } catch (Throwable th) {
            exceptionMonitor.monitor(makeEvent(th));
            throw th;
        }
    }

    public void setExceptionMonitor(ExceptionMonitor exceptionMonitor) {
        this.exceptionMonitor = exceptionMonitor;
    }

    protected ExceptionMonitorEvent makeEvent(Throwable th) {
        return new ExceptionMonitorEvent(th);
    }
}
